package com.svnservices.hannibal.dao;

import com.svnservices.domaininterface.SvnInfo;
import com.svnservices.hannibal.activerecord.SvnInfoAR;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; 
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import hannibal.dao.db.spring.Dao;

import java.sql.ResultSet;
import java.sql.SQLException;

@javax.annotation.Generated
(
	value="hannibal.generator.Generator",
	comments="",
	date = ""
)
   
public class SvnInfoDao
	extends Dao
{
	protected SvnInfoDao(javax.sql.DataSource _dataSource)
	{
		super(_dataSource);
	}

	protected ParameterizedRowMapper<SvnInfoAR> mapper = new ParameterizedRowMapper<SvnInfoAR>()
	{
		public SvnInfoAR mapRow(ResultSet _resultSet, int _rowNum)
				throws SQLException
		{
			SvnInfoAR svnInfo = new SvnInfoAR();

			svnInfo.setName(hannibal.util.DatabaseUtil.getString(_resultSet, "name"));
			svnInfo.setAuthor(hannibal.util.DatabaseUtil.getString(_resultSet, "author"));
			svnInfo.setDate(hannibal.util.DatabaseUtil.getString(_resultSet, "date"));
			svnInfo.setMessage(hannibal.util.DatabaseUtil.getString(_resultSet, "message"));
			svnInfo.setRevision(hannibal.util.DatabaseUtil.getString(_resultSet, "revision"));
			
			return svnInfo;
		}
	};

	public java.util.Collection<SvnInfoAR> collect(int _offset, int _limit, String _orderBy)
	{
		String sql = "SELECT name AS name, author AS author, date AS date, message AS message, revision AS revision FROM SvnInfo ORDER BY :orderBy LIMIT ? OFFSET ?";
		sql = sql.replaceAll(":orderBy", _orderBy);

		return query(sql, this.mapper, _limit, _offset);
	}

	public int insert(SvnInfoAR _svnInfo)
	{
		final String sql = "INSERT INTO SvnInfo ( name, author, date, message, revision) VALUES ( ?, ?, ?, ?, ?)";
		
		return update(sql, _svnInfo.getName(), _svnInfo.getAuthor(), _svnInfo.getDate(), _svnInfo.getMessage(), _svnInfo.getRevision());
	}


	public SvnInfo get(final java.lang.String _name)
	{
		final String sql = "SELECT name AS name, author AS author, date AS date, message AS message, revision AS revision FROM SvnInfo WHERE name = ?";

		return queryForObject(sql, this.mapper, _name);
	}

	public SvnInfo get(SvnInfoAR _svnInfo)
	{
		return get(_svnInfo.getName());
	}

	public int update(SvnInfoAR _svnInfo)
	{
		final String sql = "UPDATE SvnInfo SET author = ?, date = ?, message = ?, revision = ? WHERE name = ?";

		return update(sql, _svnInfo.getAuthor(), _svnInfo.getDate(), _svnInfo.getMessage(), _svnInfo.getRevision(), _svnInfo.getName() );
	}

	public int del(final java.lang.String _name)
	{
		return delete(_name);
	}

	public int delete(final java.lang.String _name)
	{
		final String sql = "DELETE FROM SvnInfo WHERE name = ?";

		return update(sql, _name);
	}

	public int del(SvnInfoAR _svnInfo)
	{
		return delete(_svnInfo);
	}

	public int delete(SvnInfoAR _svnInfo)
	{
		return delete(_svnInfo.getName());
	}


}